<html>
<head><meta charset="utf-8"><title>lazy_static and spin · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html">lazy_static and spin</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169312177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169312177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169312177">(Jun 29 2019 at 21:07)</a>:</h4>
<p>After doing <code>cargo update</code> of a tiny test project, I noticed that lazy_static now depends on <code>spin</code>. Looking at the Cargo.toml, seems that's a non-default feature, but something must be enabling that feature. (I can't find out what though, there are only two reverse dependencies according to <code>cargo tree</code> and neither of them seems to be the one...)<br>
Isn't that a problem? This will mean that when a lazy_static takes a bit to initialize, everyone waiting will wait by spinning instead of properly putting the thread to sleep. Spinlocks make sense when you know exactly that nobody will be in the critical section for too long, but doing this <em>for all lazy_static in the entire program</em> seems a bit too much?</p>



<a name="169312221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169312221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169312221">(Jun 29 2019 at 21:08)</a>:</h4>
<p>the reverse tree is:</p>
<div class="codehilite"><pre><span></span>lazy_static v1.3.0
├── c2-chacha v0.2.2
│   └── rand_chacha v0.2.0
│       └── rand v0.7.0
│           [dev-dependencies]
│           └── cargo-miri-test v0.1.0 (/home/r/src/rust/miri/test-cargo-miri)
└── getrandom v0.1.5
    ├── rand v0.7.0 (*)
    └── rand_core v0.5.0
        ├── rand v0.7.0 (*)
        ├── rand_chacha v0.2.0 (*)
        ├── rand_hc v0.2.0
        │   [dev-dependencies]
        │   └── rand v0.7.0 (*)
        └── rand_pcg v0.2.0
            └── rand v0.7.0 (*)
            [dev-dependencies]
            └── rand v0.7.0 (*)
</pre></div>


<p>but the "forwards" tree shows that spin is definitely imported:</p>
<div class="codehilite"><pre><span></span>lazy_static v1.3.0
└── spin v0.5.0
</pre></div>



<a name="169312344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169312344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169312344">(Jun 29 2019 at 21:13)</a>:</h4>
<p>there's no way to ask cargo why a feature got enabled, is there? :/</p>



<a name="169312977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169312977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169312977">(Jun 29 2019 at 21:33)</a>:</h4>
<p>There isn’t, no.</p>



<a name="169312980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169312980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169312980">(Jun 29 2019 at 21:33)</a>:</h4>
<p>what you want to see is the reverse tree of <code>spin</code>, not <code>lazy_static</code></p>



<a name="169313099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313099">(Jun 29 2019 at 21:37)</a>:</h4>
<p>good point</p>



<a name="169313140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313140">(Jun 29 2019 at 21:38)</a>:</h4>
<p>well, that doesnt bring up anything else though:</p>
<div class="codehilite"><pre><span></span>spin v0.5.0
└── lazy_static v1.3.0
    ├── c2-chacha v0.2.2
    │   └── rand_chacha v0.2.0
    │       └── rand v0.7.0
    │           [dev-dependencies]
    │           └── cargo-miri-test v0.1.0 (/home/r/src/rust/miri/test-cargo-miri)
    └── getrandom v0.1.5
        ├── rand v0.7.0 (*)
        └── rand_core v0.5.0
            ├── rand v0.7.0 (*)
            ├── rand_chacha v0.2.0 (*)
            ├── rand_hc v0.2.0
            │   [dev-dependencies]
            │   └── rand v0.7.0 (*)
            └── rand_pcg v0.2.0
                └── rand v0.7.0 (*)
                [dev-dependencies]
                └── rand v0.7.0 (*)
</pre></div>



<a name="169313314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313314">(Jun 29 2019 at 21:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I <em>think</em> getrandom is at fault</p>



<a name="169313316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313316">(Jun 29 2019 at 21:44)</a>:</h4>
<p><a href="https://github.com/rust-random/getrandom/blob/master/Cargo.toml#L32" target="_blank" title="https://github.com/rust-random/getrandom/blob/master/Cargo.toml#L32">https://github.com/rust-random/getrandom/blob/master/Cargo.toml#L32</a></p>



<a name="169313324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313324">(Jun 29 2019 at 21:45)</a>:</h4>
<p>Cargo IIRC doesn't actually respect cfg flags for feature resolution</p>



<a name="169313327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313327">(Jun 29 2019 at 21:45)</a>:</h4>
<p>but I might be wrong, so take that with a grain of salt</p>



<a name="169313658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313658">(Jun 29 2019 at 21:57)</a>:</h4>
<p>oh, well that would explain it</p>



<a name="169313659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313659">(Jun 29 2019 at 21:57)</a>:</h4>
<p>though arguably lazy_static is at fault for letting any crate opt-in to do this, globally.</p>



<a name="169313661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/lazy_static%20and%20spin/near/169313661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/lazy_static.20and.20spin.html#169313661">(Jun 29 2019 at 21:57)</a>:</h4>
<p>or am I unnecessarily worried about spinlocks being used here?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>